package cn.dnui_yxk801.dnuifood_16110100801.controller;


import android.os.Bundle;
import android.support.constraint.ConstraintLayout;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import cn.dnui_yxk801.dnuifood_16110100801.Adapter.ShopAdapter;
import cn.dnui_yxk801.dnuifood_16110100801.R;
import cn.dnui_yxk801.dnuifood_16110100801.bean.CollectBean;
import cn.dnui_yxk801.dnuifood_16110100801.bean.ResultBean;
import cn.dnui_yxk801.dnuifood_16110100801.bean.ShopBean;
import cn.dnui_yxk801.dnuifood_16110100801.iface.ShopIface;
import cn.dnui_yxk801.dnuifood_16110100801.listener.OnRetrofitListener;
import cn.dnui_yxk801.dnuifood_16110100801.model.ShopModel;


/**
 * A simple {@link Fragment} subclass.
 */
public class Fragment1 extends Fragment implements OnRetrofitListener<List<ShopBean>> {
    private View view;//定义view用来设置fragment的layout
    private RecyclerView recyclerView;//定义RecyclerView
    //定义以goodsentity实体类为对象的数据集合
    private ArrayList<ShopBean> shopsList = new ArrayList<>();
    //自定义recyclerveiw的适配器
    private ShopAdapter shopAdapter;
    private List<ShopBean> list;


    public Fragment1() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {


        view = inflater.inflate(R.layout.fragment1, container, false);
        initRecyclerView();
        return view;
    }

    private void initRecyclerView() {
        recyclerView = view.findViewById(R.id.recyclerview);
        //创建默认的线性
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
        // 设置布局管理器
        recyclerView.setLayoutManager(layoutManager);
        //如果可以确定每个item的高度是固定的，设置这个选项可以提高性能
        recyclerView.setHasFixedSize(true); //创建并设置Adapter
        //list = getData();
        initData();

    }


    void initData() {
        ShopModel shopModel = new ShopModel();
        shopModel.getAllShops(this);

    }

    @Override
    public void onSuccess(List<ShopBean> shops, int flag) {
        shopAdapter = new ShopAdapter(getActivity(), shops);
        recyclerView.setAdapter(shopAdapter);
    }



    @Override
    public void onFalure(String msg) {

    }
}
